// Angular Version 6 below need to be deleted {providedIn: 'root'}

// angular
import {Injectable} from '@angular/core';
import {HttpParams} from '@angular/common/http';
// owner
import {Request} from 'pengesoft-ng-lib';
// models
import {CommentVOList} from '../domains/commentVOList';

/**
 * 
 */
@Injectable({
  providedIn: 'root'
})
export class CommentServiceSvr {
  private readonly baseUrl: string;

  constructor(
    private request: Request
  ) {
    this.baseUrl = 'commentServiceSvr.assx/';
  }

  
  saveComment(token: string, customerId: string, houseId: string, comments: string, score: number): Promise<number> {
    const httpParams = new HttpParams()
      .append('token', token.toString())
      .append('customerId', customerId.toString())
      .append('houseId', houseId.toString())
      .append('comments', comments.toString())
      .append('score', score.toString());
    return this.request.post<number>(this.baseUrl + 'saveComment', httpParams).then((res) => {
      return res;
    });
  }

  
  listCommentsForFront(token: string, houseId: string): Promise<CommentVOList> {
    const httpParams = new HttpParams()
      .append('token', token.toString())
      .append('houseId', houseId.toString());
    return this.request.post<CommentVOList>(this.baseUrl + 'listCommentsForFront', httpParams).then((res) => {
      return res;
    });
  }

  
  listComments(token: string, houseName: string, customerName: string, deleted: number, skip: number, size: number): Promise<CommentVOList> {
    const httpParams = new HttpParams()
      .append('token', token.toString())
      .append('houseName', houseName.toString())
      .append('customerName', customerName.toString())
      .append('deleted', deleted.toString())
      .append('skip', skip.toString())
      .append('size', size.toString());
    return this.request.post<CommentVOList>(this.baseUrl + 'listComments', httpParams).then((res) => {
      return res;
    });
  }

  
  deleteComment(token: string, id: string): Promise<number> {
    const httpParams = new HttpParams()
      .append('token', token.toString())
      .append('id', id.toString());
    return this.request.post<number>(this.baseUrl + 'deleteComment', httpParams).then((res) => {
      return res;
    });
  }

  
  GetVersion(): Promise<string> {
    const httpParams = new HttpParams();
    return this.request.post<string>(this.baseUrl + 'GetVersion', httpParams).then((res) => {
      return res;
    });
  }

  
  getCommentScore(token: string, houseId: string): Promise<number> {
    const httpParams = new HttpParams()
      .append('token', token.toString())
      .append('houseId', houseId.toString());
    return this.request.post<number>(this.baseUrl + 'getCommentScore', httpParams).then((res) => {
      return res;
    });
  }
}
